package com.tjx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tjx.constant.RedisKeyPrefix;
import com.tjx.controller.PackageDetailController;
import com.tjx.entity.PackageDetail;
import com.tjx.entity.ParkPackage;
import com.tjx.mapper.ParkPackageMapper;
import com.tjx.service.IParkPackageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tjx.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 套餐表 服务实现类
 * </p>
 *
 * @author tjx
 * @since 2025-10-29
 */
@Service
public class ParkPackageServiceImpl extends ServiceImpl<ParkPackageMapper, ParkPackage> implements IParkPackageService {
    private final RedisUtils redisUtils;

    @Autowired
    ParkPackageMapper parkPackageMapper;

    public ParkPackageServiceImpl(RedisUtils redisUtils) {
        this.redisUtils = redisUtils;
    }


    @Override
    public List<ParkPackage> getAllPackages() {
        // 使用MyBatis-Plus的QueryWrapper构建查询条件
        QueryWrapper<ParkPackage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_deleted", 0); // 查询未删除的记录
        List<ParkPackage> parkPackageList = parkPackageMapper.selectList(null);

        if (parkPackageList == null || parkPackageList.isEmpty()) {
            return null;
        }

        return parkPackageList;

    }
    /**
     * 清除Redis中的套餐缓存（在套餐数据更新时调用）
     */
    public void clearPackageCache() {
        redisUtils.delete(RedisKeyPrefix.PACKAGE_LIST_KEY);
    }
}
